<template>
  <section>
    <!--工具条-->
    <el-col :span="24" class="toolbar" style="padding-bottom: 0px;">
      <el-form :inline="true" :model="filters">
        <!-- <el-form-item>
          <el-input v-model="filters.id" placeholder="ID"></el-input>
        </el-form-item> -->
        <!-- <el-form-item>
          <el-select v-model="filters.adType" placeholder="广告类别">
            <el-option label="全部类别" value=""></el-option>
            <el-option label="广告类别一" value="1"></el-option>
            <el-option label="广告类别二" value="2"></el-option>
          </el-select>
        </el-form-item> -->
        <!-- <el-select v-model="filters.toUrl" placeholder="跳转地址">
            <el-option label="全部地址" value=""></el-option>
            <el-option label="外部" value="1"></el-option>
            <el-option label="内部" value="2"></el-option>
            <el-option label="新窗口" value="3"></el-option>
          </el-select> -->
        <!--  <el-form-item label="跳转地址"  prop="productCname">
              <el-input v-model="filters.toUrl"  auto-complete="off"></el-input>
          </el-form-item> -->
        <!-- <el-form-item>
          <el-input v-model="filters.productEname" placeholder="产品英文名"></el-input>
        </el-form-item> -->
        <!-- <el-form-item>
          <el-date-picker v-model="filters.date" type="daterange" placeholder="选择起止日期范围" style="width:100%;"></el-date-picker>
        </el-form-item> -->
        <el-form-item>
          <el-select v-model="filters.isShow" clearable style="width:200px;" size="small" placeholder="请选择是否显示">
            <!-- <el-option label="全部显示状态" value="-1"></el-option> -->
            <el-option label="是" value="1"></el-option>
            <el-option label="否" value="0"></el-option>
          </el-select>
        </el-form-item>
        <el-form-item style="float:right;">
          <el-button size="small" class="button_style" type="primary" icon="upload2" @click="export2Excel" v-show="exportBtnVisible">导出</el-button>
        </el-form-item>
        <el-form-item style="float:right;">
          <el-button type="primary" class="button_style" size="small" icon="plus" @click="handleAdd" v-show="addBtnVisible">新增</el-button>
        </el-form-item>
        <el-form-item style="float:right;">
          <el-button type="primary" class="button_style" size="small" icon="search" v-on:click="getAds" v-show="queryBtnVisible">查询</el-button>
        </el-form-item>

      </el-form>
    </el-col>

    <!--列表-->
    <el-table :data="Ads" stripe border :height="winHeight-192" highlight-current-row v-loading="listLoading" @selection-change="selsChange" style="width: 100%;">
      <el-table-column type="selection" :reserve-selection="true" width="55">
      </el-table-column>
      <el-table-column prop="serialNo" label="序号" width="120" sortable>
      </el-table-column>
      <el-table-column prop="toType" label="跳转方式" width="150" :formatter="formatToType">
      </el-table-column>
      <!-- <el-table-column prop="imgUrl" label="图片地址" width="180" sortable>
      </el-table-column> -->
      <el-table-column prop="isShow" label="是否显示" width="100" :formatter="formatisShow">
      </el-table-column>

      <!-- <el-table-column prop="description" label="描述" min-width="200" sortable>
      </el-table-column> -->
      <el-table-column prop="remark" label="备注" min-width="120">
      </el-table-column>

      <el-table-column prop="startDate" label="开始时间" min-width="160">
      </el-table-column>
      <el-table-column prop="endDate" label="结束时间" min-width="160">
      </el-table-column>

      <el-table-column prop="productId" label="产品ID" min-width="160">
      </el-table-column>
      <!-- <el-table-column prop="adType" label="广告类别" width="120" > -->
      <!-- </el-table-column> -->
      <el-table-column label="操作" fixed='right' width="150">
        <template scope="scope">
          <el-button size="small" type="warning" @click="handleEdit(scope.$index, scope.row)" v-show="updateBtnVisible">修改</el-button>
          <!-- <el-button type="warning" size="small"  @click="handleAction(scope.$index, scope.row)">发布活动</el-button> -->
          <el-button type="danger" size="small" @click="handleDel(scope.$index, scope.row)" v-show="deleteBtnVisible">删除</el-button>
        </template>
      </el-table-column>
    </el-table>

    <!--工具条-->
    <el-col :span="24" class="toolbar">
      <el-button v-show="batchDeleteBtnVisible" type="danger" size="small" @click="batchRemove" :disabled="this.sels.length===0">批量删除</el-button>
      <!-- <el-pagination layout="prev, pager, next" @current-change="handleCurrentChange" :page-size="10" :total="total" style="float:right;">
      </el-pagination> -->

      <el-pagination style="float:right" @size-change="handleSizeChange" @current-change="handleCurrentChange" :current-page="page" :page-sizes="[10, 20, 40, 80]" :page-size="pageSize" layout="total, sizes, prev, pager, next, jumper" :total="total">
      </el-pagination>

    </el-col>
    <!--修改界面-->
    <el-dialog title="修改" size="small" v-model="editFormVisible" :close-on-click-modal="false">
      <!-- <el-dialog  size="small" v-model="editFormVisible" :close-on-click-modal="false">
    <div class="dialog_title_style">
    修改
    </div> -->
      <el-form :model="editForm" label-width="120px" :rules="editFormRules" ref="editForm">
        <el-row :gutter="20">
        </el-row>
        <el-row :gutter="20">
          <el-col :xs="24" :sm="20" :md="16" :lg="11">
            <el-form-item label="是否显示:" prop="isShow">
              <el-select v-model="editForm.isShow" class="otherWidth" placeholder="是否显示">
                <el-option label="是" value="1"></el-option>
                <el-option label="否" value="0"></el-option>
              </el-select>
            </el-form-item>
          </el-col>
          <el-col v-show="IsproductId" :xs="24" :sm="20" :md="16" :lg="11">
            <el-form-item label="产品:" prop="productId">
              <!--  <el-select v-model="editForm.toUrl"  :span="24"  placeholder="跳转地址">
                      <el-option label="外部" value="1"></el-option>
                      <el-option label="内部" value="2"></el-option>
                      <el-option label="新窗口" value="3"></el-option>

                    </el-select> -->
              <!-- <el-input v-model="editForm.productId"  auto-complete="off"></el-input> -->
              <el-cascader v-model="editproductId" :options="productdata" :show-all-levels="false" class="otherWidth"></el-cascader>
            </el-form-item>
          </el-col>
          <el-col v-show="IsadType" :xs="24" :sm="20" :md="16" :lg="11">
            <el-form-item label="显示时间:" prop="adType">
              <el-input v-model="editForm.adType" placeholder="请输入显示时间(秒)" auto-complete="off"></el-input>
            </el-form-item>
          </el-col>
        </el-row>
        <el-row :gutter="20">
          <el-col :xs="24" :sm="20" :md="16" :lg="11">
            <el-form-item label="序号:" prop="serialNo" :rules="[
      { required: true, message: '请输入序号'}]">
              <el-input v-model="editForm.serialNo" auto-complete="off"></el-input>
            </el-form-item>
          </el-col>
          <el-col :xs="24" :sm="20" :md="16" :lg="11">
            <!-- <el-form-item label="广告类别" prop="aname">
                      <el-select v-model="editForm.adType" :span="24" >
                        <el-option label="广告类别1" value="0"></el-option>
                        <el-option label="广告类别2" value="1"></el-option>
                        <el-option label="广告类别3" value="2"></el-option>
                    </el-select>
                  </el-form-item> -->
            <el-form-item label="跳转方式:" prop="toType">
              <el-select v-model="editForm.toType" @change="toTypeChange" class="otherWidth">
                <el-option label="内部跳转" value="0"></el-option>
                <el-option label="外部跳转" value="1"></el-option>
                <el-option label="电话号码" value="2"></el-option>
                <el-option label="内部渲染" value="3"></el-option>
                <el-option label="产品跳转" value="4"></el-option>
                <el-option label="弹出广告" value="5"></el-option>
                <el-option label="弹出全屏广告" value="6"></el-option>
                <el-option label="内置活动-红包" value="7"></el-option>
              </el-select>
            </el-form-item>
          </el-col>
        </el-row>
        <el-row :gutter="20">
          <el-col :xs="24" :sm="20" :md="16" :lg="11">
            <el-form-item label="开始时间:" prop="startDate">
              <el-date-picker v-model="editForm.startDate" type="datetime" style="width:100%;" placeholder="请选择开始时间">
              </el-date-picker>
            </el-form-item>
          </el-col>
          <el-col :xs="24" :sm="20" :md="16" :lg="11">
            <el-form-item label="结束时间:" prop="endDate">
              <el-date-picker v-model="editForm.endDate" type="datetime" style="width:100%;" placeholder="请选择结束时间">
              </el-date-picker>
            </el-form-item>
          </el-col>
        </el-row>
        <el-form-item v-show="Isupload" label="图片地址" prop="name">
          <!--  <el-input v-model="editForm.introduceUrl"  auto-complete="off"></el-input> -->
          <el-upload class="upload-demo" :action="picURL" :on-success="editSuccessUrl" :on-remove="editRemoveUrl" :file-list="fileList2" list-type="picture">
            <el-button size="small" type="primary">点击上传</el-button>
            <!-- <div slot="tip" class="el-upload__tip">只能上传jpg/png文件，且不超过500kb</div> -->
          </el-upload>
        </el-form-item>
        <el-form-item label="描述:" prop="name">
          <el-input v-model="editForm.description" auto-complete="off"></el-input>
        </el-form-item>
        <el-form-item label="备注:" prop="name">
          <el-input v-model="editForm.remark" auto-complete="off"></el-input>
        </el-form-item>
        <el-form-item label="活动详情:" prop="name">
          <!-- <editor ref="myTextEditors"
                       fileName="myFiles"
                      :canCrop="canCrop"
                      :uploadUrl="uploadUrl"
                      v-model="contents">
                    </editor> -->
          <!-- <div   class="kboder" @click="Detail('edit')"  style="height:120px;min-width:120px;">
                      <div  id="editDetail" class="ksboder">
                      </div>
                    </div> -->
          <el-input type="textarea" :rows="2" placeholder="请输入活动详情" v-model="editForm.detail">
          </el-input>
        </el-form-item>
      </el-form>
      <div slot="footer" class="dialog-footer">
        <el-button @click.native="editFormVisible = false">取消</el-button>
        <el-button type="primary" @click.native="editSubmit" :loading="editLoading">提交</el-button>
      </div>
    </el-dialog>

    <!--新增界面-->
    <el-dialog title="新增" v-model="addFormVisible" :close-on-click-modal="false">
      <!-- <el-dialog   v-model="addFormVisible" :close-on-click-modal="false">
    <div class="dialog_title_style">
    新增
    </div> -->
      <el-form :model="addForm" label-width="120px" :rules="addFormRules" ref="addForm">

        <el-row :gutter="20">
          <el-col :xs="24" :sm="20" :md="16" :lg="11">
            <el-form-item label="是否显示:" prop="isShow">
              <el-select v-model="addForm.isShow" class="otherWidth" placeholder="是否显示">
                <el-option label="是" value="1"></el-option>
                <el-option label="否" value="0"></el-option>
              </el-select>
            </el-form-item>
          </el-col>
          <el-col v-show="IsproductId" :xs="24" :sm="20" :md="16" :lg="11">
            <el-form-item label="产品:" prop="productId">
              <!--  <el-select v-model="addForm.toUrl"  :span="24" placeholder="跳转地址">
                        <el-option label="外部" value="1"></el-option>
                        <el-option label="内部" value="2"></el-option>
                        <el-option label="新窗口" value="3"></el-option>
                      </el-select> -->
              <!-- <el-input v-model="addForm.productId"  auto-complete="off"></el-input> -->
              <el-cascader v-model="addproductId" :options="productdata" :show-all-levels="false" class="otherWidth"></el-cascader>
            </el-form-item>
          </el-col>
          <el-col v-show="IsadType" :xs="24" :sm="20" :md="16" :lg="11">
            <el-form-item label="显示时间:" prop="adType">
              <el-input v-model="addForm.adType" placeholder="请输入显示时间(秒)" auto-complete="off"></el-input>
            </el-form-item>
          </el-col>
        </el-row>
        <el-row :gutter="20">
          <el-col :xs="24" :sm="20" :md="16" :lg="11">
            <!-- <el-form-item label="广告类别" prop="aname">
                        <el-select v-model="addForm.adType" :span="24">
                          <el-option label="广告类别1" value="0"></el-option>
                          <el-option label="广告类别2" value="1"></el-option>
                          <el-option label="广告类别3" value="2"></el-option>
                      </el-select> -->
            <!-- </el-form-item> -->
            <el-form-item label="序号:" prop="serialNo">
              <el-input v-model="addForm.serialNo" auto-complete="off"></el-input>
            </el-form-item>
          </el-col>
          <el-col :xs="24" :sm="20" :md="16" :lg="11">
            <el-form-item label="跳转方式:" prop="toType">
              <el-select v-model="addForm.toType" @change="toTypeChange" class="otherWidth">
                <el-option label="内部跳转" value="0"></el-option>
                <el-option label="外部跳转" value="1"></el-option>
                <el-option label="电话号码" value="2"></el-option>
                <el-option label="内部渲染" value="3"></el-option>
                <el-option label="产品跳转" value="4"></el-option>
                <el-option label="弹出活动" value="5"></el-option>
                <el-option label="弹出全屏显示活动" value="6"></el-option>
                <el-option label="内置活动" value="7"></el-option>
              </el-select>
            </el-form-item>
          </el-col>
        </el-row>
        <el-row :gutter="20">
          <el-col :xs="24" :sm="12" :md="6" :lg="11">
            <el-form-item label="开始时间:" prop="startDate">
              <el-date-picker v-model="addForm.startDate" type="datetime" style="width:100%;" placeholder="请选择开始时间">
              </el-date-picker>
            </el-form-item>
          </el-col>
          <el-col :xs="24" :sm="12" :md="6" :lg="11">
            <el-form-item label="结束时间:" prop="endDate">
              <el-date-picker v-model="addForm.endDate" type="datetime" style="width:100%;" placeholder="请选择结束时间">
              </el-date-picker>
            </el-form-item>
          </el-col>
        </el-row>
        <!--  <el-form-item label="图片地址" prop="aname">
                    <el-input  v-model="addForm.imgUrl" auto-complete="off" /></el-input>
                </el-form-item> -->
        <el-form-item v-show="Isupload" label="图片地址" prop="name">
          <!--  <el-input v-model="editForm.introduceUrl"  auto-complete="off"></el-input> -->
          <el-upload class="upload-demo" :action="picURL" :on-success="addSuccessUrl" :on-remove="addRemoveUrl" :file-list="fileList1" list-type="picture">
            <el-button size="small" type="primary">点击上传</el-button>
            <!-- <div slot="tip" class="el-upload__tip">只能上传jpg/png文件，且不超过500kb</div> -->
          </el-upload>
        </el-form-item>
        <el-form-item label="描述" prop="name">
          <el-input type="textarea" v-model="addForm.description" auto-complete="off"></el-input>
        </el-form-item>
        <el-form-item label="备注" prop="name">
          <el-input type="textarea" v-model="addForm.remark" auto-complete="off"></el-input>
        </el-form-item>
        <el-form-item label="活动详情" prop="name">
          <!-- <editor ref="myTextEditor"
                       fileName="myFile"
                      :canCrop="canCrop"
                      :uploadUrl="uploadUrl"
                      v-model="content">
                    </editor> -->
          <!--  <div   class="kboder" @click="Detail('add')" style="height:120px;min-width:120px;">
                      <div  id="addDetail" class="ksboder">
                      </div>
                    </div> -->

          <el-input type="textarea" :rows="2" placeholder="请输入活动详情" v-model="addForm.detail">
          </el-input>
        </el-form-item>

      </el-form>
      <div slot="footer" class="dialog-footer">
        <el-button @click.native="addFormVisible = false">取消</el-button>
        <el-button type="primary" @click.native="addSubmit" :loading="addLoading">提交</el-button>
      </div>
    </el-dialog>

    <!--活动界面-->
    <el-dialog title="活动" size="small" v-model="actionVisible" :close-on-click-modal="false">
      <!-- <template>
                      <div class="components-container"> -->
      <!-- <button @click="getUEContent()">获取内容</button> -->
      <!--        <div class="editor-container">
                          <UE  :defaultMsg=defaultMsg :config=config :id=ue1 ref="ue"></UE>
                        </div>
                      </div>
                    </template> -->
      <div slot="footer" class="dialog-footer">
        <el-button @click.native="actionVisible = false">取消</el-button>
        <el-button type="primary" @click.native="acitonSubmit" :loading="actionLoading">提交</el-button>
      </div>
    </el-dialog>

    <el-dialog title="修改" size="large" v-model="editorVisible" :close-on-click-modal="false">
      <editor ref="myTextEditor" :fileName="'myFile'" :canCrop="canCrop" :uploadUrl="uploadUrl" v-model="content">
      </editor>
      <div slot="footer" class="dialog-footer">
        <el-button @click.native="editorVisible = false">取消</el-button>
        <el-button type="primary" @click.native="editorSubmit" :loading="editorLoading">确定</el-button>
      </div>
    </el-dialog>
  </section>
</template>

<script>
import commons from '../../common/js/common'
import { mapState, mapActions } from 'vuex';
import util from '../../common/js/util'
//import NProgress from 'nprogress'
import { getAdListPage, removeAd, batchRemoveUser, editAd, addAd, picURL, getAdDetail, updateAdDetail, base, productByRisk } from '../../api/api';

import editor from '../../components/Quilleditor.vue'
export default {
  components: {
    editor
  },
  data() {
    return {
      canCrop: false,
      /*测试上传图片的接口，返回结构为{url:''}*/
      uploadUrl: base + '/cxb/admin/uploadWeb/upload',
      content: '',
      ue1: 'ue1',
      ue2: 'ue2',
      actionId: '',
      editor1: null,
      tempAciton: '',
      filters: {
        adType: '',
        toUrl: '',
        isShow: ''
      },
      productdata: [],
      addproductId: [],
      editproductId: [],
      Ads: [],
      picURL: picURL,
      total: 0,
      page: 1,
      pageSize: 10,
      listLoading: false,
      sels: [],//列表选中列
      fileList1: [],
      fileList2: [],
      IsadType: false,
      Isupload: true,
      IsproductId: true,
      actionVisible: false,//活动界面是否显示
      actionLoading: false,
      editFormVisible: false,//修改界面是否显示
      editLoading: false,
      editorVisible: false,
      editorLoading: false,
      commonObj: '',
      editFormRules: {
        isShow: [
          { required: true, message: '请选择显示状态', trigger: 'blur' }
        ],
        productId: [
          { required: true, message: '请选择产品', trigger: 'blur' }
        ],
        // serialNo: [
        //   { required: true, message: '请输入序号', trigger: 'blur' }
        // ],
        toType: [
          { required: true, message: '请选择跳转方式', trigger: 'blur' }
        ]
      },
      //修改界面数据
      editForm: {
        serialNo: '',
        adType: '',
        imgUrl: '',
        productId: '',
        toType: '',
        isShow: '',
        description: '',
        remark: '',
        detail: '',
        startDate: '',
        endDate: ''
      },

      addFormVisible: false,//新增界面是否显示
      addLoading: false,
      addFormRules: {
        isShow: [
          { required: true, message: '请选择显示状态', trigger: 'blur' }
        ],
        productId: [
          { required: true, message: '请选择产品', trigger: 'blur' }
        ],
        serialNo: [
          { required: true, message: '请输入序号', trigger: 'blur' }
        ],
        toType: [
          { required: true, message: '请选择跳转方式', trigger: 'blur' }
        ]
      },
      //新增界面数据
      addForm: {
        serialNo: '',
        adType: '',
        imgUrl: '',
        productId: '',
        toType: '',
        isShow: '',
        description: '',
        remark: '',
        detail: '',
        startDate: '',
        endDate: ''
      },

      queryBtnVisible: false,
      addBtnVisible: false,
      exportBtnVisible: false,
      updateBtnVisible: false,
      deleteBtnVisible: false,
      batchDeleteBtnVisible: false
    }
  },
  computed: mapState([
    'winWidth',
    'winHeight'
  ]),
  methods: {
    ...mapActions([
      'ProductList'
    ]),
    getUEContent() {
      let content = this.$refs.ue.getUEContent();

      this.$notify({
        title: '获取成功，可在控制台查看！',
        message: content,
        type: 'success'
      });
    },
    formatisShow: function (row, column) {
      return row.isShow == '1' ? '是' : '否';
    },
    formatToType: function (row, column) {
      return commons.ToType(row.toType);
    },
    formatTime: function (row, column) {
      return commons.getDaytime(row.startDate, 1, false);
    },
    formatTime1: function (row, column) {
      return commons.getDaytime(row.endDate, 1, false);
    },
    //跳转方式change
    toTypeChange: function (value) {
      if (value == '5' || value == '6') {
        this.IsadType = true;
        this.IsproductId = false;
        this.Isupload = false;
      }
      else if (value == '7') {
        this.IsadType = false;
        this.IsproductId = false;
        this.addFormRules.productId[0].required = false;
        this.editFormRules.productId[0].required = false;
      }
      else {
        this.IsadType = false;
        this.Isupload = true;
        this.IsproductId = true;
      }
    },
    products: function () {
      var riskCodelist = this.$store.state.riskCodelist.result;
      var productlist = this.$store.state.productList;
      if (riskCodelist) {
        for (var i in riskCodelist) {
          this.productdata.push({
            value: riskCodelist[i].codeEname1,
            label: riskCodelist[i].codeType1,
            children: []
          });
        }
      }

      for (var i in this.productdata) {
        if (productlist) {
          for (var k in productlist) {
            if (productlist[k].riskCode == this.productdata[i].value) {
              this.productdata[i].children.push({
                value: productlist[k].id,
                label: productlist[k].productCname,
              });
            }
          }
        }
      }
    },
    Detail: function (str) {
      let _this = this;
      var nowTime = Date.parse(new Date());
      var string = '';
      string = 'ad/' + commons.getDaytime(nowTime, 3, false);
      _this.content = '';
      _this.editorVisible = true;
      if (str == "add") {
        _this.content = $('#addDetail').html();
        _this.commonObj = 'addDetail';
      }
      else {
        _this.content = $('#editDetail').html();
        _this.commonObj = 'editDetail';
      }
      _this.$store.commit('EDITORPICTURE_VALUE', string);
    },
    handleCurrentChange(val) {
      this.page = val;
      this.getAds();
    },
    handleSizeChange(val) {
      this.pageSize = val;
      this.getAds();
    },
    //上传图片
    addSuccessUrl(response, file, fileList) {
      this.addForm.imgUrl = commons.SuccessUrl(this.addForm.imgUrl, file, true);
    },
    addRemoveUrl(file, fileList) {
      this.addForm.imgUrl = commons.RemoveUrl(this.addForm.imgUrl, file);
    },
    editSuccessUrl(response, file, fileList) {
      this.editForm.imgUrl = commons.SuccessUrl(this.editForm.imgUrl, file, true);
    },
    editRemoveUrl(file, fileList) {
      this.editForm.imgUrl = commons.RemoveUrl(this.editForm.imgUrl, file);
    },
    //获取用户列表
    getAds() {
      let para = new FormData();
      para.append("pageSize", this.pageSize);
      para.append("pageNumber", this.page);
      para.append("adType", this.filters.adType);
      para.append("toUrl", this.filters.toUrl);
      para.append("isShow", this.filters.isShow);
      this.listLoading = true;
      //NProgress.start();
      getAdListPage(para).then((res) => {
        this.total = res.data.result.totalElements;
        this.Ads = res.data.result.content;
        this.listLoading = false;
        //NProgress.done();
      });
    },
    //删除
    handleDel: function (index, row) {
      this.$confirm('确认删除该记录吗?', '提示', {
        type: 'warning'
      }).then(() => {
        this.listLoading = true;
        //NProgress.start();
        let para = new FormData();
        para.append("ids", row.id);
        removeAd(para).then((res) => {
          this.listLoading = false;
          //NProgress.done();
          this.$message({
            message: '删除成功',
            type: 'success'
          });
          this.getAds();
        });
      }).catch(() => {

      });
    },

    //table导出excel
    export2Excel: function () {
      require.ensure([], () => {
        const { export_json_to_excel } = require('../../vendor/Export2Excel');
        const tHeader = ['图片地址', '产品ID', '跳转方式', '是否显示', '描述', '备注'];
        const filterVal = ['imgUrl', 'productId', 'toType', 'isShow', 'description', 'remark'];
        const list = this.Ads;
        for (var i in list) {
          list[i].toType = commons.ToType(list[i].toType);
          list[i].isShow = commons.IsValidate(list[i].isShow);
        }
        const data = this.formatJson(filterVal, list);
        export_json_to_excel(tHeader, data, '广告配置列表excel');
      })
    },
    formatJson: function (filterVal, jsonData) {
      return jsonData.map(v => filterVal.map(j => v[j]))
    },

    //显示修改界面
    handleEdit: function (index, row) {
      let _this = this;
      _this.IsadType = false;
      _this.Isupload = true;
      _this.IsproductId = true;
      _this.editFormVisible = true;
      _this.fileList2 = [];
      _this.editproductId = [];
      _this.editForm = Object.assign({}, row);
      if (_this.editForm.toType == "5") {
        _this.IsadType = true;
        _this.Isupload = false;
      } else if (_this.editForm.toType == "7") {
        _this.IsproductId = false;
        _this.editFormRules.productId[0].required = false;
      }
      else {
        _this.IsadType = false;
        _this.Isupload = true;
      }
      if (_this.editForm.productId) {
        var productlist = this.$store.state.productList;
        for (var i in productlist) {
          if (parseInt(productlist[i].id) == parseInt(_this.editForm.productId)) {
            _this.editproductId.push(productlist[i].riskCode);
            _this.editproductId.push(productlist[i].id);
            break;
          }
        }
      }
      var URL1 = row.imgUrl.split(",")
      if (URL1.length > 0 && URL1[0] != "") {
        for (var i in URL1) {
          _this.fileList2.push({
            name: commons.interceptName(URL1[i]),
            url: URL1[i]
          });
        }
      }
      else {
        _this.fileList2 = [];
      }
      _this.editForm.imgUrl = URL1.join(',');

      let para = new FormData();

      _this.actionId = row.id;
      para.append('id', row.id);
      getAdDetail(para).then((res) => {
        try {
          $('#editDetail').html(res.data.result.detail);
        }
        catch (err) {

        }
      });
      // _this.$refs.ue.editor.body.innerHTML = row.detail;
    },
    //显示新增界面
    handleAdd: function () {
      let _this = this;
      _this.addFormVisible = true;
      _this.IsadType = false;
      _this.Isupload = true;
      _this.IsproductId = true;
      _this.addForm = {
        serialNo: '',
        adType: '',
        imgUrl: '',
        productId: '',
        toType: '',
        isShow: '',
        description: '',
        remark: '',
        detail: '',
        startDate: '',
        endDate: ''
      };
      _this.addproductId = [];
      try {
        _this.$refs.myTextEditor.content = '';
      }
      catch (err) {

      }
      // _this.$refs.myTextEditor.content = '';
      // this.$refs.ue1.editor.body.innerHTML = '';
      // let para = {
      //   id: parseInt(this.addForm.id),
      //   productCname: this.addForm.productCname,
      //   productEname: this.addForm.productEname,
      //   deadLine: this.addForm.deadLine,
      //   maxAge: parseInt(this.addForm.maxAge),
      //   minAge: parseInt(this.addForm.minAge),
      //   priPrice: parseFloat(this.addForm.priPrice),
      //   startDate: this.addForm.startDate,
      //   endDate: this.addForm.endDate
      // };

    },

    //显示活动界面handleAction


    // handleAction:function(index, row){
    //   let _this = this;
    //   _this.actionVisible = true;
    //   let para = new FormData();
    //   _this.actionId = row.id;
    //   para.append('id',row.id);

    //   getAdDetail(para).then((res) => {
    //     this.$refs.ue.editor.body.innerHTML = res.data.result.detail;
    //   });
    // },
    //活动提交
    // acitonSubmit: function(){
    //   var data = this.$refs.ue.editor.body.innerHTML;
    //   let para = new FormData();
    //   para.append('id',this.actionId);
    //   para.append('detail',data);
    //   this.$confirm('确认提交吗？', '提示', {}).then(() => {
    //     this.actionLoading = true;
    //     updateAdDetail(para).then((res) => {
    //         this.$message({
    //             message: '发布成功',
    //             type: 'success'
    //         });
    //         this.actionVisible = false;
    //     }).catch(() => {
    //           this.$message({
    //             message: '发布异常',
    //             type: 'error'
    //           });
    //           this.actionLoading = false;
    //     });
    //   });

    // },
    //修改
    editSubmit: function () {
      // this.editForm.detail = this.contents;
      this.$refs.editForm.validate((valid) => {
        if (this.IsproductId == true) {
          this.editForm.productId = this.editproductId[this.editproductId.length - 1].toString();
        }
        if (valid) {
          this.$confirm('确认提交吗？', '提示', {}).then(() => {
            this.editLoading = true;
            //NProgress.start();
            let para = this.editForm;
            // para.startDate = (!para.startDate || para.startDate == '') ? '' : util.formatDate.format(new Date(para.startDate), 'yyyy-MM-dd');
            // para.endDate = (!para.endDate || para.endDate == '') ? '' : util.formatDate.format(new Date(para.endDate), 'yyyy-MM-dd');
            para.startDate = new Date(para.startDate);
            para.endDate = new Date(para.endDate);
            editAd(para).then((res) => {
              this.editLoading = false;
              //NProgress.done();
              this.$message({
                message: '提交成功',
                type: 'success'
              });
              this.$refs['editForm'].resetFields();
              this.editFormVisible = false;
              this.getAds();
            }).catch(() => {
              this.$message({
                message: '数据异常',
                type: 'error'
              });
              this.editLoading = false;
            });
          });
        }
      });
    },
    //新增
    addSubmit: function () {
      // this.addForm.detail = this.content;
      this.$refs.addForm.validate((valid) => {
        if (this.IsproductId == true) {
          this.addForm.productId = this.addproductId[this.addproductId.length - 1].toString();
        }
        if (valid) {
          this.$confirm('确认提交吗？', '提示', {}).then(() => {
            this.addLoading = true;
            //NProgress.start();
            // let para = Object.assign({}, this.addForm);
            let para = this.addForm;
            // para.startDate = (!para.startDate || para.startDate == '') ? '' : util.formatDate.format(new Date(para.startDate), 'yyyy-MM-dd');
            // para.endDate = (!para.endDate || para.endDate == '') ? '' : util.formatDate.format(new Date(para.endDate), 'yyyy-MM-dd');
            para.startDate = Date.parse(para.startDate);
            para.endDate = Date.parse(para.endDate);
            addAd(para).then((res) => {
              this.addLoading = false;
              //NProgress.done();
              this.$message({
                message: '提交成功',
                type: 'success'
              });
              this.$refs['addForm'].resetFields();
              this.addFormVisible = false;
              this.getAds();
            }).catch(() => {
              this.$message({
                message: '数据异常',
                type: 'error'
              });
              this.addLoading = false;
            });
          });
        }
      });
    },
    //修改器确定
    editorSubmit: function () {
      let _this = this;
      if (_this.commonObj == "addDetail") {
        $('#addDetail').html(_this.content);
        _this.addForm.detail = _this.content;
      }
      else if (_this.commonObj == "editDetail") {
        $('#editDetail').html(_this.content);
        _this.editForm.detail = _this.content;
      }
      _this.editorVisible = false;
    },
    selsChange: function (sels) {
      this.sels = sels;
    },
    //批量删除
    batchRemove: function () {
      var ids = this.sels.map(item => item.id).toString();
      this.$confirm('确认删除选中记录吗？', '提示', {
        type: 'warning'
      }).then(() => {
        this.listLoading = true;
        //NProgress.start();
        // let para = { ids: ids };
        let para = new FormData();
        para.append("ids", ids);
        removeAd(para).then((res) => {
          this.listLoading = false;
          //NProgress.done();
          this.$message({
            message: '删除成功',
            type: 'success'
          });
          this.getAds();
        });
      }).catch(() => {

      });
    },

    btnShow: function () {
      let thisData = JSON.parse(sessionStorage.getItem('142'));
      let _this = this;
      $.each(thisData, function (i, j) {
        if (thisData[i] == "advertQuery") {
          _this.queryBtnVisible = true;
        }
        if (thisData[i] == "advertAdd") {
          _this.addBtnVisible = true;
        }
        if (thisData[i] == "advertExport") {
          _this.exportBtnVisible = true;
        }
        if (thisData[i] == "advertUpdate") {
          _this.updateBtnVisible = true;
        }
        if (thisData[i] == "advertRemove") {
          _this.deleteBtnVisible = true;
        }
        if (thisData[i] == "advertBatchRemove") {
          _this.batchDeleteBtnVisible = true;
        }
      });
    }
  },
  mounted() {
    // alert(this.count);
    // this.$store.commit('INCREMENT','1');
    this.getAds();
    this.products();
    this.btnShow();
    // this.content=this.value
    // $('#que1').
  }
}

</script>

<style>
.content-container {
  padding: 5px !important;
  padding-top: 0px !important;
}

.kboder {
  border: 1px solid #bfcbd9;
  overflow-y: scroll;
  overflow-x: hidden;
  cursor: pointer;
}
.ksboder {
  margin: 10px;
  word-wrap: break-word;
}
.otherWidth {
  width: 100%;
}
</style>